package lab03.test07;

import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;

public class test {
    public static void main(String[] args) {

        String path = "E:\\java  test\\lab03test07\\test.zip";

        ZipInputStream zipInputStream = null;
        try {
            zipInputStream = new ZipInputStream(new FileInputStream(path));
            ZipFile zipFile = new ZipFile(path);

            ZipEntry entry;

            while ((entry = zipInputStream.getNextEntry()) != null) {
                System.out.println(entry.getName());
            }
            //创建test文件夹
            File testFile = new File("E:\\java  test\\lab03test07\\test1");
            testFile.mkdir();

            //字节流 读文件 写文件
            InputStream inputStream = zipFile.getInputStream(entry);
            FileOutputStream fileOutputStream = new FileOutputStream
                    (new File("E:\\java  test\\lab03test07\\test1\\" + entry));

            byte[] data = new byte[1024];
            while ((inputStream.read(data)) != -1) {
                fileOutputStream.write(data);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                zipInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
